#include "buzzer.h"
#include "delay.h"

extern uint8_t button_press_flag;//判断是否要响按键音

void buzzer_init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_ResetBits(GPIOB,GPIO_Pin_9);
	BUZZER_OFF;
}


//按键按下响200ms
void si12_press(void)
{
	BUZZER_ON;
	delay_ms(50);
	BUZZER_OFF;
}

//成功响
void si12_succced(void)
{
	BUZZER_ON;
	delay_ms(360);
	BUZZER_OFF;
	button_press_flag = 1;
}

//失败响
void si12_fail(void)
{
	uint8_t i;
	for(i=0;i<3;i++)
	{
		BUZZER_ON;
		delay_ms(70);
		BUZZER_OFF;
		delay_ms(50);
	}
	button_press_flag = 1;
}
